/*
 * @lc app=leetcode.cn id=482 lang=rust
 *
 * [482] 密钥格式化
 */

// @lc code=start
impl Solution {
    pub fn license_key_formatting(s: String, k: i32) -> String {
        let mut s = s.clone().replace("-", "");
        
        
        if s.len() <= k as usize { return s.to_uppercase();}

        let first_k:usize = s.len() % k as usize;
        let mut ret = String::from(&s[0..first_k]);

        if first_k > 0{
            ret += "-";
        }

        let k = k as usize;
        let mut i = first_k;
        while i < s.len() - k {
            ret += &s[i..i+k];
            ret += "-";
            i += k;
        }

        ret += &s[s.len() - k..];

        return ret.to_uppercase();
    }
}
// @lc code=end

